package
{
	import control.*;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.Security;
	import flash.utils.getTimer;
	
	import flash3.framework.LayerManager;
	import flash3.net.NetFacade;
	
	import global.HtmlConnect;
	
	import model.GlobalModel;
	
	import net.CoreGroup;
	
	import spark.core.SpriteVisualElement;
	
	import view.layer.*;
	
	[SWF(width="830",height="731",frameRate="25",backgroundColor="#FFFFFF")]
	public class ChessLobby extends SpriteVisualElement
	{
		public static var common:Sprite	= new Sprite();
		public static var layer:Sprite	= new Sprite();
		public static var select:Sprite	= new Sprite();
		public static var chat:Sprite	= new Sprite();
		public static var cover:Sprite	= new Sprite();
		public static var dialog:Sprite	= new Sprite();
		public static var loader:Sprite	= new Sprite();
		public static var tops:Sprite		= new Sprite();
		public static var masks:Bitmap = null;
		
		private var gc:GlobalControl;
		private var loadTime:Number = 0;
		
		public function ChessLobby()
		{
			HtmlConnect.notifyServerLoadEnd();
			
			addChild(common);
			addChild(layer);
			addChild(select);
			addChild(chat);
			addChild(cover);
			addChild(dialog);
			addChild(loader);
			addChild(tops);
			gc = new GlobalControl();
//			stage.stageFocusRect = false;
	
			var bd:BitmapData = new BitmapData(830, 731, false, 0x000000);
			masks = new Bitmap(bd);
			masks.alpha = 0.5;
			masks.visible = false;
			cover.addChild(masks);
			
			NetFacade.i.init(true);
			LayerManager.i.container = layer;
			LayerManager.i.add(L.L_Login, LayerLogin);
			LayerManager.i.add(L.L_Loader, LayerLoader);
			LayerManager.i.add(L.L_Lobby, LayerLobby);
			LayerManager.i.add(L.L_Game, LayerGame);
			LayerManager.i.add(L.L_SelTable, LayerSelTable);
			LayerManager.i.changeState(GlobalModel.loginMode==GlobalModel.LOGIN_MODE_LOCAL ? L.L_Login : L.L_Loader);
			
			loadTime = getTimer();
			this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		private function onEnterFrame(evt:Event):void
		{
			if(LayerManager.i.curState == L.L_Lobby)
			{
				this.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
//				netRequestLoadTime();
			}
		}
		
		private function netRequestLoadTime():void
		{
			var time:Number = getTimer() - loadTime;
			NetFacade.i.send(CoreGroup.MDM_KN_COMMAND, CoreGroup.SUB_KN_LOADTIME, time);
		}
	}
}